<template>
  <a-modal 
    :visible="visible"
    :title="title"
    okText="确定" 
    cancelText="取消"
    :maskClosable="false"
    :destroyOnClose="true"
    :keyboard="false"
    @cancel="closeModal()"
    @ok="handleSubmit"
    width="500px">
    <a-checkbox-group v-model="distributionConditions" @change="handleCheckboxChange">
        <a-checkbox style="display:block;line-height:40px; margin-left: 8px;" :value="1">新用户注册发放</a-checkbox>
        <a-checkbox style="display:block;line-height:40px;" :value="2">一笔消费满 <a-input-number v-model="price" :min="0" :max="99999999" :precision="2"></a-input-number> 元发放</a-checkbox>
        <!-- <a-checkbox style="display:block;line-height:40px;" :value="3">用户获得权限卡发放 
            <a href="javascript:;" @click="showEquityCard=true" v-if="distributionConditions.includes(3)">请选择权益卡</a>
        </a-checkbox> -->
    </a-checkbox-group>
    <EquityCardList :visible="showEquityCard" @cancel="showEquityCard=false;"></EquityCardList>
  </a-modal>
</template>

<script>
import EquityCardList from './EquityCardList';
//import deepCopy from '@/utils/deepCopy';

export default {
  components:{
    EquityCardList
  },
  props: {
    visible:{
      type:Boolean,
      default:false,
    },
    selectedKeys:{
      type:Array,
      default(){
        return [];
      }
    },
    params:{
      type:Object,
      default(){
        return {};
      }
    }
  },
  watch:{
    visible(newVal){
      if(newVal){
        this.price=this.params.price || 0;
        this.distributionConditions=this.selectedKeys;
        console.log(this.params,this.price,this.distributionConditions);
      }
    }
  },
  computed:{
    title(){
      return '请选择发放条件';
    }
  },
  data() {
    return {
      distributionConditions:[],
      price:null,
      showEquityCard:false,
    }
  },
  created(){
    
  },
  mounted () {
  },
  methods: {
    closeModal (freshTable) {
      this.$emit('cancel', freshTable)
    },
    handleCheckboxChange(){

    },
    handleSubmit(){
      console.log('this.distributionConditions',this.distributionConditions,this.price);
      if(this.distributionConditions.length==0){
        this.$message.error('请选择一项发放条件');
        return;
      }
      if(this.distributionConditions.includes(2)){
        if(this.price<=0){
          this.$message.error('请填写价格');
          return;
        }
      }
      else {
        this.price=null;
      }
      this.$emit('submit',this.distributionConditions,{
        price:this.price
      });
    }
  }
}
</script>

<style lang="less" scoped>

</style>
